<?php

namespace App\Admin\Controllers;

use App\Models\Menu;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class MenuController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Menu(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('menu_name');
            $grid->column('pid');
            $grid->column('is_menu') ->using([0 => '否', 1 => '是'])
                ->dot(
                    [
                        0 => 'danger',
                        1 => 'success',
                        2 => \Admin::color()->info(),
                    ],
                    'primary' // 第二个参数为默认值
                );
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Menu(), function (Show $show) {
            $show->field('id');
            $show->field('menu_name');
            $show->field('pid');
            $show->field('is_menu');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Menu(), function (Form $form) {
            $form->display('id');
            $form->text('menu_name');
            $form->text('pid');
            $form->text('is_menu');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
